<script setup lang="ts">
import { TagsOutlined } from "@ant-design/icons-vue";
import type { TagVo } from "@/type/post";
import { useRouter } from "vue-router";
import { onMounted, ref } from "vue";
import { tagApi } from "@/api";

const router = useRouter();
const tags = ref<TagVo[]>([]);
const getTagList = async () => {
  const res = await tagApi.getTagList();
  tags.value = res.list;
};
onMounted(() => {
  getTagList();
});
</script>

<template>
  <div class="bg-white rounded-lg shadow-sm p-6">
    <h3 class="text-lg font-bold mb-4">标签云</h3>
    <div class="flex flex-wrap gap-2">
      <a-tag
        v-for="tag in tags"
        :key="tag.name"
        :color="tag.color"
        @click="router.push(`/tag-article/${tag.name}/${tag.id}`)"
        class="cursor-pointer"
      >
        {{ tag.name }}
        <template #icon>
          <tags-outlined />
        </template>
      </a-tag>
    </div>
  </div>
</template>

<style scoped></style>
